import fetchApi from "./request";
export const baseUrl = "http://localhost:3001";
import { UserInfo } from "@/pages/User";
const Headers = (CT = 'application/json', args = {}) => ({ headers: { 'Content-Type': CT }, ...args })
export const getDataByType = (type: number, page: number, limit: number) => {
    return fetchApi(`${baseUrl}/animal/getDataByType?type=${type}&page=${page}&limit=${limit}`);
}
export const getAllType = () => {
    return fetchApi(`${baseUrl}/animal/getAllType`);
}
export const getDataById = (id: number) => {
    return fetchApi(`${baseUrl}/animal/getDataById?id=${id}`);
}
export const postLogin = (data: UserInfo) => {
    return fetchApi(`${baseUrl}/user/postLogin`, {
        method: 'POST',
        ...Headers(),
        body: JSON.stringify(data)
    });
}
export const postRegister = (data: Partial<UserInfo>) => {
    return fetchApi(`${baseUrl}/user/postRegister`, {
        method: 'POST',
        ...Headers(),
        body: JSON.stringify(data)
    });
}
export const getCollectLog = (uid: number | string) => {
    return fetchApi(`${baseUrl}/collect/getCollectLog?uid=${uid}`);
}
export const toggleCollect = (uid: number | string, did: number | string) => {
    return fetchApi(`${baseUrl}/collect/toggleCollect?uid=${uid}&did=${did}`);
}

export const getCollectState = (uid: number | string, did: number | string) => {
    return fetchApi(`${baseUrl}/collect/getCollectState?uid=${uid}&did=${did}`);
}
export const changeMessage = ({ acc, password, oldPassword, nick_name }: Partial<UserInfo>) => {
    return fetchApi(`${baseUrl}/user/putMessage?acc=${acc}&password=${password}&oldPassword=${oldPassword}&nick_name=${nick_name}`, {
        method: 'PUT',
    });
}
export const setWeb = (uid: number | string, did: number | string) => {
    return fetchApi(`${baseUrl}/web/setWeb?uid=${uid}&did=${did}`);
}
export const deleteWeb = (uid: number | string, did: number | string) => {
    return fetchApi(`${baseUrl}/web/deleteWeb?uid=${uid}&did=${did}`);
}
export const getWeb = (uid: number | string) => {
    return fetchApi(`${baseUrl}/web/getWeb?uid=${uid}`);
}
// /animal/getDataLikeName
export const getDataLikeName = (name: string, page: number) => {
    return fetchApi(`${baseUrl}/animal/getDataLikeName?name=${name}&page=${page}`);
}
export const getOssSignature = () => {
    return fetchApi(`${baseUrl}/user/getOssSignature`);
}
export const changeAvatarById = async (host: string, formData: FormData, url: string, id: number) => {
    await fetch(`${host}`, {
        method: 'POST',
        body: formData
    })
    return fetchApi(`${baseUrl}/user/setAvator?url=${url}&id=${id}`)
}